import request from "../utils/request.js";

/**
 * 用户登录
 * @param username 账号
 * @param password 密码
 * @param callback 回调函数
 */
export async function userLogin(username, password, callback) {
    await request.get('/user/login', {
        params: {
            username: username,
            password: password
        }
    }).then((result) => {
        callback(result)
    })
}

/**
 * 用户注册
 * @param registerInfo 用户注册信息
 * @param callback 回调函数
 */
export async function userRegister(registerInfo, callback) {
    await request.post('/user/register', registerInfo).then(result => {
        callback(result)
    })
}


export async function userPageListAndSearch(user,callback) {
    await  request.post('/user/pageListAndSearch',user).then(result=>{
        callback(result)
    })
}


export async function deleteByIds(ids,callback) {
    await  request.post('/user/deleteByIds',ids).then(result=>{
        callback(result)
    })
}

export async function deleteById(id,callback) {
    await  request.post(`/user/delete/${id}`).then(result=>{
        callback(result)
    })
}

export async function unFreezeUserById(id,callback) {
    await  request.post(`/user/unFreezeUserById/${id}`).then(result=>{
        callback(result)
    })
}



export async function freezeUserById(id,callback) {
    await  request.post(`/user/freezeUserById/${id}`).then(result=>{
        callback(result)
    })
}


export async function freezeUsersByIds(users,callback) {
    await  request.post('/user/freezeUsersByIds',JSON.stringify(users)).then(result=>{
        callback(result)
    })
}



export async function unFreezeUsersByIds(users,callback) {
    await  request.post('/user/unFreezeUsersByIds',JSON.stringify(users)).then(result=>{
        callback(result)
    })
}


export async function resetPass(id,callback) {
    await  request.post(`/user/resetpassword/${id}`).then(result=>{
        callback(result)
    })
}



export async function getCode(username,email,callback) {
    await  request.get('/user/getCode',{
        params:{
            username:username,
            email:email
        }
    }).then(result=>{
        callback(result)
    })
}


export async function forgetPass(code,password,email,callback) {
    await  request.get('/user/verifyAndChangePass',{
        params:{
            code:code,
            password:password,
            email:email
        }
    }).then(result=>{
        callback(result)
    })
}

export async function searchUser(callback) {
    await  request.post(`/user/searchUser`).then(result=>{
        callback(result)
    })
}




export async function updateUser(user,callback) {
    await  request.post(`/user/update`,user).then(result=>{
        callback(result)
    })
}


export async function userLogout(callback) {
    await  request.post(`/user/logout`).then(result=>{
        callback(result)
    })
}

export async function changePass(password,callback) {
    await  request.get('/user/changePassword',{
        params:{
            password:password,
        }
    }).then(result=>{
        callback(result)
    })
}

export async function changeUserStorageSize(user, callback) {
    await request.post('/user/changeStorageSize', user).then(callback)
}
